//
//  HMComposeBtn.swift
//  GuoGuo
//
//  Created by 艾小新 on 16/8/12.
//  Copyright © 2016年 xiaoxin. All rights reserved.
//

import UIKit

class HMComposeBtn: UIButton {
    
    override var highlighted: Bool {
        
        get {
            
            return false
            
        }
        set {
            
        }
    }
    
    
    var composeModel :HMComposeModel? {
        
        didSet {
   
            setTitle(composeModel!.title!, forState: .Normal)
            setImage(UIImage(named: composeModel!.icon!), forState: UIControlState.Normal)
            
        }
    }
    
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        // 文字居中
        titleLabel?.textAlignment = .Center
        // 文字颜色
        setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        // 文字大小
        titleLabel?.font = UIFont.systemFontOfSize(16)
        // 让图片原样显示
        imageView?.contentMode = .Center
   
    }
    
    // 布局子控件，这里面更改UIButton本来的样式
    override func layoutSubviews() {
        
        super.layoutSubviews()
        let width = self.bounds.width
        let height = self.bounds.height
        
        // 设置图片的 大小 / 位置
        imageView?.frame.size = CGSizeMake(width, width)
        imageView?.frame.origin = CGPoint(x: 0, y: 0)
        
        // 设置文字的 大小 / 位置
        titleLabel?.frame.size = CGSizeMake(width, height - width)
        titleLabel?.frame.origin = CGPoint(x: 0, y: width)
        
        
        
    }
    
    

}
